package com.koron.css2.newProjectCenter.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.koron.css2.ServerInterface;
import com.koron.css2.newProjectCenter.bean.PjMaterialBean;
import com.koron.css2.newProjectCenter.bean.query.PjMaterialQueryBean;
import com.koron.css2.newProjectCenter.mapper.PjMaterialMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

/**
 * 工程报装-工程材料列表查询
 */
public class PjMaterialList implements ServerInterface {
    @Override
    public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
        try {
            PjMaterialQueryBean pjMaterialQuery = JsonUtils.objectToPojo(req.getData(), PjMaterialQueryBean.class);
            PageHelper.startPage(pjMaterialQuery.getPage(), pjMaterialQuery.getPageCount());
            PjMaterialMapper pjMaterialMapper = factory.getMapper(PjMaterialMapper.class);
            // 2. 查询数据
            List<PjMaterialBean> pjMaterialList = pjMaterialMapper.selectList(pjMaterialQuery);
            // 3. 返回结果
            MessageBean<PageInfo> messageBean = MessageBean.create(Constant.MESSAGE_INT_SUCCESS,"工程材料列表查询成功", PageInfo.class);
            messageBean.setData(new PageInfo(pjMaterialList));
            return messageBean;
        } catch (Exception e) {
            logger.error("工程材料列表查询失败" + e);
        }
        return MessageBean.create(Constant.MESSAGE_INT_FAIL,"工程材料列表查询失败",null);
    }
}
